<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
	<script type="text/javascript">
		$(function () {
		    //alert("我在轮播图页面");
            $('#bannerDatagrid').datagrid({
                url:'${pageContext.request.contextPath}/banner/selectBannerDatagrid',
                method:"get",
                pagination:true,
                columns:[[
                    //一旦加上复选框属性，页面展示不出来效果，刷新后表格对不齐
					{field:'恶心',title:'复选框',checkbox:true},
                    {field:'bannerId',title:'编号',width:50,align:"center"},
                    {field:'bannerOldName',title:'名称',width:100,align:"center"},
                    {title:"轮播图片",field:"bannerImageUrl" ,
						formatter: function (value, row, index) {
                            return "<img width='60px' height='45px' src='${pageContext.request.contextPath}" + row.bannerImageUrl + "'/>";
                        }},
                    {field:'bannerDate',title:'上传日期',width:150,align:"center"},
                    {field:'bannerDescription',title:'描述',width:100,align:"center"}
                ]],
                toolbar: '#myBannerTooBar'
            });

            //隐藏添加轮播图界面
            $('#addBannerDialog').dialog({
                title: '添加界面',
                width: 400,
                height: 400,
                closed: true,
                modal:true,
                draggable:true,
                resizable:true
            });
        });
		// 打开添加会话框
		function toAddBannerDialog() {
            $('#addBannerDialog').dialog("open");
        }
        // 执行添加操作
		function doAddBannerForm() {
            $('#addBannerForm').form('submit', {
				url:"${pageContext.request.contextPath}/banner/addBanner",
                onSubmit: function(){
                // do some check
                return true;
            },
            success:function(data){
                //后台执行成功之后的回调函数
                var data = JSON.parse(data);

                if(data.isAdd){
                    $("#addBannerDialog").dialog("close");
                    $("#bannerDatagrid").datagrid("reload");
                }else{
                    alert("添加失败");
                }
            }
        });
        }
        function doDeleteSomeBanners() {
			var allSelectionRows=$("#bannerDatagrid").datagrid("getSelections");
			if(allSelectionRows.length==0){
			    alert("请选择要删除的数据！");
			}else{
                var isConfirm=confirm("请确认是否删除？");
                if(isConfirm){
                    var allIds=new Array(allSelectionRows.length);
                    for(var i=0;i<allIds.length;i++){
                        allIds[i]=allSelectionRows[i].bannerId;
                    }
                    //发送ajax请求
                    $.ajax({
                        url:"${pageContext.request.contextPath}/banner/deleteSomeBanners",
                        data:"ids="+allIds,
                        success:function(data){
                            //删除成功，刷新页面
                            if(data.isDelete){
                                $("#bannerDatagrid").datagrid("reload");
                            }else{
                                alert("删除失败，请确认！");
                            }
                        }
                    })
				}
			}
        }
	</script>
	<div id="myBannerTooBar">
		<a class="easyui-linkbutton" onclick="toAddBannerDialog()">添加</a>
		<a class="easyui-linkbutton" onclick="doDeleteSomeBanners()">删除</a>
	</div>
	<table id="bannerDatagrid"></table>

<%-------------------------------添加轮播图页面开始------------------%>
	<div id="addBannerDialog">
		<form id="addBannerForm" method="post" enctype="multipart/form-data">
			<table align="center">
				<tr align="center">
					<td>轮播图名称</td>
					<td><input  name="bannerOldName"/></td>
				</tr>
				<tr align="center">
					<td>轮播图</td>
					<td>
						<input name="mf" type="file"/>
					</td>
				</tr>
				<tr align="center">
					<td>上传日期</td>
					<td>
						<input class="Wdate" type="text" name="bannerDate" onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'2008-03-08 11:30:00',maxDate:'2100-03-10 20:59:30'})">
					</td>
				</tr>
				<tr align="center">
					<td>描述</td>
					<td><textarea  name="bannerDescription"></textarea></td>
				</tr>
				<tr align="center">
					<td colspan="2">
						<input type="button" onclick="doAddBannerForm()" value="添加"/>
					</td>
				</tr>
			</table>
		</form>
	</div>

<%------------------------------------添加轮播图页面结束------------------------%>

